﻿using System;
using System.Collections.Generic;
using System.Linq;
using AdvCMS.Data.Linq;
using System.Text;
using AdvCMS.Data.Repositories;
// Created By AdvGen
// URL : http://www.itblogs.info
// URL : http://www.advgen.com
namespace AdvCMS.Data.Linq.Repositories
{
    public class PageRepository : IPageRepository
    {
        public AdvCMS.Data.Linq.PagesDataContext   DataContext { get; set; }
        public IAdvPage Create()
        {
            return new AdvPage();
        }

        public IList<IAdvPage> FindAll()
        {
            return DataContext.AdvPages.ToList<IAdvPage>();
        }

        public IAdvPage Get(int id)
        {
            return DataContext.AdvPages.FirstOrDefault(x => x.Id == id);
        }
        public IAdvPage GetPage(string name)
        {
            return DataContext.AdvPages.FirstOrDefault(x => x.PageName == name);
        }

        public void Insert(IAdvPage page)
        {
            DataContext.AdvPages.InsertOnSubmit((AdvPage)page);
        }

        public void Delete(IAdvPage page)
        {
            DataContext.AdvPages.DeleteOnSubmit((AdvPage)page);
        }

        public void Update()
        {
            DataContext.SubmitChanges();
        }
        
    }
}
